# -*- coding: utf-8 -*-
# @Time : 2022/8/5 下午2:54
# @Author : WangYunfei
# @FileName: demo9.py
# @Email: yunfei.wang@innvote.com
"""
9. 采集本站点前4页数据，字段不限，站点：https://ggzy.jcs.gov.cn/website/transaction/index。交付：提供数据和代码截图即可。说明：禁止使用自动化等技术
"""
import requests
from example.kaoshi.demo7 import BTCMongoDB


class GOV(object):

    def __init__(self):
        self.url = "https://ggzy.jcs.gov.cn/pro-api-construction/construction/bidder/bidSection/list"
        self.mongo = BTCMongoDB("gov", db="kaoshi")

    def get_data(self):
        for i in range(1, 5):
            params = {
                "pageNum": i,
                "pageSize": "20",
                "releaseTime": "",
                "search": "",
                "informationType": "ANNOUNCEMENT",
                "departmentId": "",
                "projectType": "SZFJ",
                "informationName": "ZBGG"
            }
            res = requests.get(url=self.url, params=params)
            yield res.json()["rows"]

    def save_data(self, data: list):
        for item in data:
            item["_id"] = item.pop("projectId")
            self.mongo.insert_one(item)

    def run(self):
        for page_data in self.get_data():
            self.save_data(page_data)


if __name__ == '__main__':
    GOV().run()





